#ifndef __FLASH_H
#define __FLASH_H

#include "../utils/error.h"

namespace driver::flash {

constexpr uint32_t SECTOR_SIZE = 1024 * 1;

constexpr uint32_t BOOT_ADDR = 0x08000000;
constexpr uint32_t BOOT_SIZE = 10 * 1024;

constexpr uint32_t APP_ADDR = BOOT_ADDR + BOOT_SIZE;
constexpr uint32_t APP_SIZE = 26 * 1024;

constexpr uint32_t OTA_DATA_ADDR = APP_ADDR + APP_SIZE;
constexpr uint32_t OTA_DATA_SIZE = APP_SIZE;

constexpr uint32_t OTA_INFO_ADDR = OTA_DATA_ADDR + OTA_DATA_SIZE;
constexpr uint32_t OTA_INFO_SIZE = SECTOR_SIZE;

constexpr uint32_t DATA_ADDR = OTA_INFO_ADDR + OTA_INFO_SIZE;
constexpr uint32_t DATA_SIZE = SECTOR_SIZE;

void read(uint32_t addr, void *buf, uint32_t size); // ALIGN 2
utils::Error erase(uint32_t addr, uint32_t size);
utils::Error write(uint32_t addr, const void *buf, uint32_t size);

} // namespace driver::flash

#endif
